package com.javabi.unix.delimited;

import static com.javabi.unix.util.Numbers.parseFirstInt;
import static com.javabi.unix.util.Numbers.parseFirstLong;

import java.util.LinkedHashMap;
import java.util.Map;

public class DelimitedMap {

	private final Map<String, String> map = new LinkedHashMap<String, String>();

	public String get(String key) {
		return map.get(key);
	}

	public int getInt(String key, int defaultValue) {
		String value = get(key);
		if (value == null) {
			return defaultValue;
		}
		return parseFirstInt(value);
	}

	public long getLong(String key, long defaultValue) {
		String value = get(key);
		if (value == null) {
			return defaultValue;
		}
		return parseFirstLong(value);
	}

	public void put(String key, String value) {
		if (key == null) {
			throw new NullPointerException("key");
		}
		if (value == null) {
			throw new NullPointerException("value");
		}
		map.put(key, value);
	}

	public boolean isEmpty() {
		return map.isEmpty();
	}
}
